home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 220 / 220.d81 / t.state caps < prev    next >
Text File  |  2022-08-26  |  5KB  |  208 lines

  1. u
  2.      S T A T E   C A P I T A L S
  3.  
  4.       Program by Kenneth Barsky
  5.          Text by Dave Moorman
  6.  
  7.  
  8.     Ken is back with one of his great
  9. quiz programs. There's nothing to it
  10. -- just type in the name of the
  11. Capital City for the displayed State.
  12. Ken has also included a list of facts
  13. to which you might want to pay
  14. attention.
  15.  
  16.     One great feature of this and
  17. other Barsky Quizes is that mistakes
  18. are not fatal. The State is just
  19. shuffled into the stack and will come
  20. up again. And again. Sooner or later,
  21. you will certainly get it right!
  22.  
  23. [NOTE:] Beta Tester Robin Harbron from
  24. Thunder Bay, Ontario asks, "What
  25. percentage of subscribers are non-USA?
  26. This program assumes a us audience.
  27. 'Your' State (Provence) Capitals are
  28. completely different in Canada or
  29. Australia."
  30.  
  31. Right you are! So, we need Print Shop
  32. graphics of Canadian, Australian,
  33. German, Italian, and Romanian
  34. States/Provences/Districs, along with
  35. similar information. We can put it
  36. into Ken's data file and stump us
  37. parochial USAns. Weans?
  38.  
  39.  
  40. TECH NOTES
  41.  
  42.     When I first saw this quiz, I
  43. thought it used a bitmap graphics
  44. screen with Scripter to print the
  45. text. But no -- this program uses the
  46. bottom of the font (the reverse
  47. characters) to display the state maps
  48. -- which are Print Shop graphics.
  49.  
  50.     I did a little tweaking to the
  51. program. I noted that the randomizing
  52. code was rather archaic.
  53.  
  54.  96 z=int(rnd(1)*50)+1
  55.  97 if s$(z)=""then 96
  56.  
  57.  After a state capital is correctly
  58. identified, s$(z) is made null. On the
  59. face of it, this is a fair way to grab
  60. random items -- just once each.
  61. However, as the quiz progresses, the
  62. time needed to find an active state
  63. grows longer. When just one state is
  64. left, the program -- grabbing random
  65. items -- could miss an indefinite
  66. number of times.
  67.  
  68.     A better way is to create an index
  69. then shuffle it with a FOR-NEXT loop:
  70.  
  71.  dim i(50):for x=1to50:i(x)=x:next
  72.  
  73.  (index created and loaded)
  74.  
  75.  forx=1to50:r=int(rnd(1)*50)+1
  76.  
  77.  (get a random number in R)
  78.  
  79.  i=i(x):i(x)=i(r):i(r)=i:next
  80.  
  81.  (then swap I(X) with I(R) using I)
  82.  
  83.  
  84.  THERE! Done. Count through I(X), and
  85. each number will come up once,
  86. randomly.
  87.  
  88. When a state's capital is not
  89. correctly named, I added a little
  90. random shuffle:
  91.  
  92.  r=int(rnd(1)*(t-1))+1:i=i(r):
  93.  i(r)=i(t):i(t)=i
  94.  
  95.  This way, only states still not used
  96. (1 through T-1) are swapped with I(T).
  97.  
  98.  
  99.     The next problem I found was that
  100. the program ran out of memory. Ken
  101. used the servicable technique of
  102. pulling down the Top of Basic in order
  103. to have a place for the custom font:
  104.  
  105.     poke56,56:pO55,0:clr
  106.  
  107.  Again, nothing wrong with this --
  108. until ten strings of data for 50
  109. states are loaded into arrays.
  110. The program was short and ran just
  111. fine -- until I began to fool with it!
  112.  
  113.     A better method for using custom
  114. fonts is to move UP the Bottom of
  115. Basic. This requires a boot program.
  116. We almost always have a boot program
  117. anyway, so this was no big deal.
  118.  
  119.     First, grab the title screen we
  120. usually use. Often, these are lines
  121. 41000 - 41999. Change the title and
  122. author. Then build the rest of the
  123. program:
  124.  
  125.  10 gosub41000
  126.  20 d = peek(186):ifd<8thend=8
  127.  30 a$="state capitals"
  128.  40 ?"<hm><blk><dn><dn><dn>loada$,d"
  129.  50 ?"<dn><dn><dn><dn>run<hm>
  130.  60 poke198,2:poke631,13:poke632,13
  131.  
  132.  This is fairly standard "dynamic
  133. keyboard" work. The LOAD and RUN
  134. commands are printed on the screen (in
  135. black, so they are invisible) in such
  136. a way that two RETURNS will execute
  137. the commands. Locations 631 and 632
  138. are poked with 13's (RETURNS), and 198
  139. is poked with 2. Nothing will happen
  140. until the program ENDs.
  141.  
  142.     Now for pushing up the Bottom of
  143. Basic:
  144.  
  145.  70 q=16:pO44,q:pOq*256,0
  146.  
  147.  I use Q to set the page where Basic
  148. will begin. Normally, Basic starts at
  149. 2049 -- page 8, byte 1. We want to put
  150. the font at 2048, so we are moving
  151. Basic up to 4097 (page 16, byte 1).
  152. Location 43 holds the byte byte (1),
  153. so no reason to fool with it. Just
  154. poke 44 with q. Also, the byte just
  155. before the bottom of Basic MUST be 0.
  156. so we poke q*256 with 0.
  157.  
  158.     That's all there is to it. If you
  159. want to Bload files, you can do that
  160. also in the boot program. Once you
  161. have changed the Bottom of Basic, you
  162. can continue to do most anything
  163. except a GOTO or GOSUB.
  164.  
  165.     When the program reaches the end,
  166. the two RETURNs are executed, LOADing
  167. the program, and RUNning it.
  168.  
  169.     Now here is the important part.
  170. Once the program is loaded to the
  171. raised Bottom of Basic, you don't have
  172. to worry about it. You can edit and
  173. save it all day long (unless you reset
  174. or shut-down). And now some 25000
  175. bytes of Basic memory are free for
  176. program and string manipulation.
  177.  
  178.     The font is now at 2048 (page 16),
  179. and to enable it, POKE 53272,18.
  180.  
  181.  NOTE: The boot was changed to load
  182. and run the linked and packed version
  183. of this program. That's a whole other
  184. story.
  185.  
  186.  
  187.     These are not the Absolute Ways of
  188. programming. They are just little
  189. tricks to make the program run better
  190. and the output cleaner. Ken writes a
  191. good program. Everything is in logical
  192. sections. So doing a little tweaking
  193. is just a fun part of my job. On the
  194. other hand, some of these tricks might
  195. be just what you need to get your
  196. program to look and act exactly the
  197. way you want it to.
  198.  
  199.     I had to link and pack "state
  200. caps.pkd" to have more of room on this
  201. side of the 1541. However, if you want
  202. to take a look, press <STOP-RESTORE>
  203. and list the program. Most of my stuff
  204. is from 20000 and on.
  205.  
  206.  DMM
  207.  
  208.  
  209.